package com.jcrj.util;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExcelUtil {
	public static HSSFWorkbook createExcelData(String tableName, String[] x, Object[][] obj) {
		HSSFWorkbook workbook = new HSSFWorkbook();
		HSSFSheet sheet = workbook.createSheet(tableName);

		HSSFCellStyle cellstyle = workbook.createCellStyle();
		cellstyle.setAlignment((short) 2);
		cellstyle.setVerticalAlignment((short) 1);
		cellstyle.setWrapText(true);
		HSSFFont font = workbook.createFont();
		font.setBoldweight((short) 700);
		font.setFontName("宋体");
		font.setFontHeight((short) 200);
		cellstyle.setFont(font);

		HSSFRow row = sheet.createRow(0);
		for (int i = 0; i < x.length; i++) {
			HSSFCell cell = row.createCell((short) i);
			cell.setCellValue(new HSSFRichTextString(x[i]));
			cell.setCellStyle(cellstyle);
		}

		for (int j = 0; j < obj.length; j++) {
			HSSFRow row1 = sheet.createRow(j + 1);
			for (int i = 0; i < x.length; i++) {
				HSSFCell cell = row1.createCell((short) i);
				if ((obj[j][i] != null) && (!"".equals(obj[j][i])))
					cell.setCellValue(new HSSFRichTextString(obj[j][i].toString()));
				else {
					cell.setCellValue(new HSSFRichTextString());
				}
			}
		}
		return workbook;
	}
}

/*
 * Location: /Volumes/work/oa/WEB-INF/classes/ Qualified Name:
 * com.jcrj.util.PoiExcelUtil JD-Core Version: 0.6.0
 */